package com.foxzzz.link;


import com.foxzzz.base.ListNode;

public class Solution203 {
    public ListNode removeElements(ListNode head, int val) {
        ListNode prev = new ListNode(-1), pA = head;
        ListNode result = prev;
        prev.next = head;
        while (pA != null) {
            while (pA != null && pA.val == val) {
                pA = pA.next;
            }
            prev.next = pA;
            prev = pA;
            if (pA != null) {
                pA = pA.next;
            }
        }
        return result.next;
    }

    public static void main(String[] args) {
        ListNode listNode = ListNode.getListNode("[6,1,6]");
        Solution203 solution203 = new Solution203();
        ListNode listNode1 = solution203.removeElements(listNode, 6);
        ListNode.visit(listNode1);
    }
}
